home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kpalette.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  6.1 KB  |  229 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1999 Waldo Bastian (bastian@kde.org)
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; version 
  7.     2 of the License.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.     Boston, MA 02110-1301, USA.
  18. */
  19. //-----------------------------------------------------------------------------
  20. // KDE color palette.
  21.  
  22. #ifndef KDELIBS_KPALETTE_H
  23. #define KDELIBS_KPALETTE_H
  24.  
  25. #include <qcolor.h>
  26. #include <qptrlist.h>
  27. #include <qstring.h>
  28. #include <qstringlist.h>
  29. #include "kdelibs_export.h"
  30.  
  31. class KPalettePrivate;
  32.  
  33. /**
  34.  * Class for handling Palettes.
  35.  *
  36.  * This class makes it easy to handle palettes.
  37.  * A palette is a set of colors. This class can read
  38.  * and write palettes from and to a file.
  39.  *
  40.  * This class uses the "GIMP" palette file format.
  41.  *
  42.  * This class is totally unrelated to QPalette.
  43.  *
  44.  * @author Waldo Bastian (bastian@kde.org)
  45.  **/
  46. class KDECORE_EXPORT KPalette
  47. {
  48. public:
  49.    /**
  50.     * Query which KDE palettes are installed.
  51.     *
  52.     * @return A list with a palette names.
  53.     */
  54.    static QStringList getPaletteList();
  55.  
  56.    /**
  57.     * KPalette constructor. Creates a KPalette from a file
  58.     * the filename is derived from the name.
  59.     * @param name The name of palette as returned by getPaletteList()
  60.     **/
  61.    KPalette(const QString &name=QString::null);
  62.  
  63.    /**
  64.     * KPalette copy constructor.
  65.     **/
  66.    KPalette(const KPalette &);
  67.  
  68.    /**
  69.     * KPalette destructor.
  70.     **/
  71.    virtual ~KPalette();
  72.    
  73.    /**
  74.     * KPalette assignment operator
  75.     **/
  76.    KPalette& operator=( const KPalette &);
  77.  
  78.    /**
  79.     * Save the palette
  80.     *
  81.     * @return 'true' if successful
  82.     **/
  83.    bool save();
  84.  
  85.    /**
  86.     * Get the description of the palette.
  87.     * @return the description of the palette.
  88.     **/
  89.    QString description() const
  90.        { return mDesc; }
  91.  
  92.    /**       
  93.     * Set the description of the palette.
  94.     * @param desc the new description
  95.     **/
  96.    void setDescription(const QString &desc)
  97.        { mDesc = desc; }
  98.    
  99.    /**
  100.     * Get the name of the palette. 
  101.     * @return the name of the palette
  102.     **/
  103.    QString name() const
  104.        { return mName; }
  105.  
  106.    /**
  107.     * Set the name of the palette.
  108.     * @param name the name of the palette
  109.     **/
  110.    void setName(const QString &name)
  111.        { mName = name; }
  112.  
  113.    /**
  114.     * Used to specify whether a palette may be edited.
  115.     * @see editable()
  116.     * @see setEditable()
  117.     */
  118.    enum Editable { Yes, ///< Palette may be edited 
  119.            No,  ///< Palette may not be edited
  120.            Ask  ///< Ask user before editing
  121.    };
  122.   
  123.    /**
  124.     * Returns whether the palette may be edited.
  125.     * @return the state of the palette
  126.     **/
  127.    Editable editable() const
  128.        { return mEditable; }
  129.  
  130.    /**
  131.     * Change whether the palette may be edited.
  132.     * @param editable the state of the palette
  133.     **/
  134.    void setEditable(Editable editable)
  135.        { mEditable = editable; }
  136.    
  137.    /**
  138.     * Return the number of colors in the palette.
  139.     * @return the number of colors
  140.     **/
  141.    int nrColors() const
  142.        { return (int) mKolorList.count(); }
  143.  
  144.    /**
  145.     * Find color by index.
  146.     * @param index the index of the desired color
  147.     * @return The @p index -th color of the palette, null if not found.
  148.     **/
  149.    QColor color(int index);
  150.    
  151.    /**
  152.     * Find index by @p color.
  153.     * @param color the color to find
  154.     * @return The index of the color in the palette or -1 if the
  155.     * color is not found.
  156.     **/
  157.    int findColor(const QColor &color) const;
  158.  
  159.    /**
  160.     * Find color name by @p index.
  161.     * @param index the index of the color
  162.     * @return The name of the @p index -th color.
  163.     * Note that not all palettes have named the colors. Null is
  164.     * returned if the color does not exist or has no name.
  165.     **/
  166.    QString colorName(int index);
  167.    
  168.    /**
  169.     * Find color name by @p color.
  170.     * @return The name of color according to this palette.
  171.     * Note that not all palettes have named the colors.
  172.     * Note also that each palette can give the same color
  173.     * a different name.
  174.     **/
  175.    QString colorName(const QColor &color)
  176.        { return colorName( findColor(color)); }
  177.    
  178.    /**
  179.     * Add a color.
  180.     * @param newColor The color to add.
  181.     * @param newColorName The name of the color, null to remove 
  182.     *                     the name.
  183.     * @return The index of the added color.
  184.     **/
  185.    int addColor(const QColor &newColor, 
  186.                 const QString &newColorName = QString::null);
  187.  
  188.    /**
  189.     * Change a color.
  190.     * @param index Index of the color to change
  191.     * @param newColor The new color.
  192.     * @param newColorName The new color name, null to remove 
  193.     *                     the name.
  194.     * @return The index of the new color or -1 if the color couldn't
  195.     * be changed.
  196.     **/
  197.    int changeColor(int index, 
  198.                    const QColor &newColor, 
  199.                    const QString &newColorName = QString::null);
  200.  
  201.    /**
  202.     * Change a color.
  203.     * @param oldColor The original color
  204.     * @param newColor The new color.
  205.     * @param newColorName The new color name, null to remove 
  206.     *                     the name.
  207.     * @return The index of the new color or -1 if the color couldn't
  208.     * be changed.
  209.     **/
  210.    int changeColor(const QColor &oldColor, 
  211.                    const QColor &newColor, 
  212.                    const QString &newColorName = QString::null)
  213.        { return changeColor( findColor(oldColor), newColor, newColorName); }
  214.  
  215. private:   
  216.    typedef struct { QColor color; QString name; } kolor;
  217.    QPtrList<kolor> mKolorList;
  218.    
  219.    QString mName;
  220.    QString mDesc;
  221.    Editable mEditable;
  222.  
  223.    KPalettePrivate *d;
  224. };
  225.  
  226.  
  227. #endif        // KDELIBS_KPALETTE_H
  228.  
  229.